/*
2021-7-14
https://ac.nowcoder.com/acm/contest/17942/I
*/

#include<iostream>

using namespace std;
typedef long long ll;

ll qpow(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}
int dfs(int x)
{
    if(x==0) return 0;
    if(x==1) return 1;
    ll cnt=0;
    for(int i=31;i>=0;i--)
    {
        if(x>>i & 1)
        {
            cnt+=qpow(2,i+1)-1-dfs(x-qpow(2,i));
            break;
        }
    }
    return cnt;
}

int main()
{
    int num;
    cin>>num;
    ll ans=0;
    ans=dfs(num);
    cout<<ans<<endl;
    return 0;
}

